<%@page import="weaver.conn.RecordSet"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="com.alibaba.fastjson.JSONObject"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="com.zlgs.cqyf.vote.ConnectionUtil"%>
<%@ page import="java.io.PrintWriter" %>
<%
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/json; charset=utf-8");
    JSONObject retObject = new JSONObject();
    retObject.put("code", 200);
    retObject.put("msg", "操作成功");
	try{
    	// URL 参数
	    Object id  = request.getParameter("id");                  // 子奖项ID
	    Object name  = request.getParameter("name");              // 子奖项名称
	    Object awardsId  = request.getParameter("awardId");              // 子奖项名称
	    
	    String querySQL = "select count(1) as count from vote_awards_subname where name = N'"+name+"' AND awards_id = " +awardsId +" and is_del = 0";
	   	System.out.println(querySQL);
	    RecordSet set = new RecordSet();
	    set.executeSql(querySQL);
	    set.next(); 
	   	if(set.getInt("count")>0){
	   		throw new RuntimeException("数据重复了!");
	   	}
	    // 跟新数据
	    String sql = "update vote_awards_subname set  name=N'"+name+"' where id="+id;
	    RecordSet set1 = new RecordSet();
	    set1.executeUpdate(sql);
    } catch (Exception e) {
        e.printStackTrace();
        retObject.put("code", -1);
        retObject.put("msg", e.getMessage());
    } finally {
        PrintWriter printWriter = response.getWriter();
        printWriter.append(retObject.toJSONString());
        if (printWriter != null)  printWriter.close();
    }
%>
 